package com.face;

import com.face.ineterceptor.WechatInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

	/**
	 * 添加拦截器
	 */
	/*
	 * @Override public void addInterceptors(InterceptorRegistry registry) {
	 * //添加登录拦截 registry.addInterceptor(new
	 * LoginInterceptors()).addPathPatterns("/**").excludePathPatterns("/login")
	 * .excludePathPatterns("/error").excludePathPatterns("/error/**").
	 * excludePathPatterns("/page/**")
	 * .excludePathPatterns("/static/**").excludePathPatterns(
	 * "/files/download/**").excludePathPatterns("/test/**")
	 * .excludePathPatterns("/user").excludePathPatterns("/wechat").
	 * excludePathPatterns("/wechat/**"); //添加文件下载拦截 registry.addInterceptor(new
	 * DownloadInterceptors()).addPathPatterns("/files/download/**"); }
	 */

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(wechatInterceptor()).addPathPatterns("/wechat/**");
	}

	/**
	 * 我们要求DispatcherServlet将对静态资源的请求转发到Servlet容
	 * 器中默认的Servlet上,而不是使用DispatcherServlet本身来处理 此类请求
	 */
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
	}


	/**
     * 支持跨域访问和跨域配置
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedMethods("OPTIONS", "GET", "POST","PUT", "DELETE", "PATCH")
                .allowedOrigins("http://47.93.205.45:8080","http://localhost:9527","http://manage.aimendian.cn",
                		"https://manage.aimendian.cn","*")
                .allowCredentials(true);
    }

    @Bean
    WechatInterceptor wechatInterceptor(){
    	return new WechatInterceptor();
	}
}
